package com.renchunlin.logindemo01.api

import com.renchunlin.logindemo01.utils.CookiesManager
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/*
 * class title: 
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/4/21.
 * PS: Not easy to write code, please indicate.
 */

/**
 * 创建Retrofit已提供API Service
 */
object RetrofitClient {

    //设置请求超时时间
    val okHttpClient: OkHttpClient = OkHttpClient.Builder()
        .cookieJar(CookiesManager())   //cookie管理
        .callTimeout(30, TimeUnit.SECONDS)
        .build()

    private val retrofit: Retrofit = Retrofit.Builder()
        .baseUrl(ApiService.BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .client(okHttpClient)
        .build()

    val apiService: ApiService = retrofit.create(ApiService::class.java)

}